package cc.hexie.fish.controller;

import cc.hexie.fish.dao.AccountDao;
import cc.hexie.fish.pojo.AccountBean;
import cc.hexie.fish.service.AccountService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/account")
public class AccountController {
    private Log logger = LogFactory.getLog(this.getClass());

    @Autowired
    AccountService accountService;

    @Autowired
    AccountDao accountDao;

    @RequestMapping("/getaccountinfo")
    @ResponseBody
    public String getAccountInfo() {
        return accountService.getAccountById(1).toString();
    }

    @RequestMapping("/getallaccount")
    @ResponseBody
    public String getAllAccount() {
        accountService.getAllAccount();
        return "getallaccount finished...";
    }

    @RequestMapping("/transAccount")
    @ResponseBody
    public String transAccount() {
        AccountBean fromAccount = accountService.getAccountById(1);
        AccountBean toAccount = accountService.getAccountById(2);

        accountService.transMoney(fromAccount, toAccount);

        return "trans finished...";
    }
}
